package com.Txunda.fxw.ui.dialog;

import android.content.Context;
import android.content.DialogInterface;
import android.view.View;

/**
 * @閿熺殕璁规嫹閿熸枻鎷烽敓闃跺府鎷烽敓閰殿煉鎷锋灇鏇伴敓鏂ゆ嫹閿燂拷:MikyouCommonDialog
 * 
 * 								Created by mikyou on 16-7-21.
 * @param dialogTitle
 *            閿熺殕浼欐嫹閿熸枻鎷疯皨閿熸枻鎷烽敓锟�
 * @param dialogMessage
 *            閿熺殕浼欐嫹閿熸枻鎷烽敓鏂ゆ嫹閿熸枻鎷烽敓锟�
 * @param positiveText
 *            閿熸枻鎷风ず閿熸枻鎷风‘閿熸枻鎷烽敓鏂ゆ嫹鍥鹃敓渚ュ府鎷烽挳閿熸枻鎷穞ext閿熶茎鎲嬫嫹
 * @param negativeText
 *            閿熸枻鎷风ず閿熸枻鎷峰彇閿熸枻鎷烽敓鏂ゆ嫹鍥鹃敓渚ュ府鎷烽挳閿熸枻鎷穞ext閿熶茎鎲嬫嫹
 * @param customeLayoutId
 *            閿熺殕浼欐嫹閿熸枻鎷烽敓鐨嗚鎷烽敓钘夊竷閿熻纰夋嫹id 閿熸枻鎷锋病閿熸枻鎷烽敓鐨嗚鎷烽敓钘夊竷閿熸枻鎷� 榛橀敓杈冭揪鎷烽敓鏂ゆ嫹0
 * @param context
 *            閿熸枻鎷烽敓鏂ゆ嫹閿熶茎璁规嫹閿熸枻鎷�
 * @param dialogView
 *            閿熺殕璁规嫹閿熻棄甯冮敓琛楃鎷稸iew閿熸枻鎷烽敓鏂ゆ嫹,閿熺粨渚涢敓鏂ゆ嫹閿熸枻鎷烽敓鏂ゆ嫹閿熺粸鐨勬帴鍖℃嫹get閿熸枻鎷穝et閿熸枻鎷烽敓鏂ゆ嫹,閿熸枻鎷烽敓鏂ゆ嫹閿熸枻鎷烽敓鏂ゆ嫹閿熺殕璁规嫹閿熸枻鎷峰嫙閿熸枻鎷烽敓鏂ゆ嫹閿熸枻鎷烽敓绲璱ew閿熸枻鎷烽敓鏂ゆ嫹姘愰敓鏂ゆ嫹閿熼ズ锟�
 * @param listener
 *            閿熸枻鎷烽敓鏂ゆ嫹閿熸枻鎷� 閿熸枻鎷烽敓鑺傛枻鎷风‘閿熸枻鎷烽敓鏂ゆ嫹鍙栭敓鏂ゆ嫹閿熸枻鎷峰浘閿熸枻鎷烽敓鏂ゆ嫹閿熸枻鎷烽敓鏂ゆ嫹閿熸枻鎷峰綍閿熸枻鎷烽敓鏂ゆ嫹閿熸枻鎷烽敓鏂ゆ嫹閿熸枻鎷烽摚閿熸彮浼欐嫹閿熸枻鎷烽敓鏂ゆ嫹閿熸枻鎷烽敓鏂ゆ嫹閿熸枻鎷烽敓鏂ゆ嫹閿熸枻鎷烽敓鎻紮鎷烽敓鏂ゆ嫹閿熻鎲嬫嫹閿熸枻鎷烽敓鏂ゆ嫹閿熸枻鎷风‘閿熸枻鎷烽敓鏂ゆ嫹鍙栭敓鏂ゆ嫹閿熸枻鎷峰浘
 */
public class MikyouCommonDialog {
	private Context context;
	private int customeLayoutId;
	private String dialogTitle;
	private String dialogMessage;
	private String positiveText;
	private String negativeText;

	private View dialogView;
	private OnDialogListener listener;

	// 閿熸枻鎷烽敓鏂ゆ嫹閿熺殕璁规嫹閿熸枻鎷穠iew閿熶茎鐧告嫹閿熸枻鎷烽敓鏂ゆ嫹
	public MikyouCommonDialog(Context context, int customeLayoutId, String dialogTitle, String positiveText,
			String negativeText) {
		this.context = context;
		this.customeLayoutId = customeLayoutId;
		this.dialogTitle = dialogTitle;
		this.positiveText = positiveText;
		this.negativeText = negativeText;
		this.dialogView = View.inflate(context, customeLayoutId, null);
	}

	// 閿熸枻鎷烽敓鏂ゆ嫹閿熺殕璁规嫹閿熸枻鎷穠iew閿熶茎鐧告嫹閿熸枻鎷烽敓鏂ゆ嫹
	public MikyouCommonDialog(Context context, String dialogMessage, String dialogTitle, String positiveText,
			String negativeText) {
		this.context = context;
		this.dialogTitle = dialogTitle;
		this.dialogMessage = dialogMessage;
		this.positiveText = positiveText;
		this.negativeText = negativeText;
	}

	public View getDialogView() {
		return dialogView;
	}

	public void setDialogView(View dialogView) {
		this.dialogView = dialogView;
	}

	public void showDialog() {
		CustomDialog.Builder dialog = new CustomDialog.Builder(context);
		dialog.setTitle(dialogTitle);// 閿熸枻鎷烽敓鐭唻鎷烽敓鏂ゆ嫹
		// 娉ㄩ敓鏂ゆ嫹:dialogMessage閿熸枻鎷穌ialogView閿熻浼欐嫹閿熸枻鎷烽敓杈冪媱璇ф嫹閿熸枻鎷烽敓绲沬alogMessage閿熸枻鎷烽敓鏂ゆ嫹dialogView閿熼叺璇ф嫹閿熸枻鎷烽敓鏂ゆ嫹,dialogView閿熸枻鎷烽敓鏂ゆ嫹閿熸枻鎷穌ialogMessage閿熼叺杈炬嫹閿熸枻鎷�
		if (dialogMessage != null) {
			dialog.setMessage(dialogMessage);// 閿熸枻鎷烽敓鐭浼欐嫹閿熸枻鎷烽敓鏂ゆ嫹閿熸枻鎷�
		} else {
			dialog.setContentView(dialogView);// 閿熸枻鎷烽敓鐭浼欐嫹閿熸枻鎷烽敓鏂ゆ嫹杩滈敓鏂ゆ嫹閿熺淡iew閿熸枻鎷烽敓鏂ゆ嫹
		}
		/**
		 * 閿熸枻鎷烽敓鏂ゆ嫹閿熸枻鎷烽敓鏂ゆ嫹閿熸枻鎷烽敓鏂ゆ嫹閿熸枻鎷峰綍閿熸枻鎷烽敓鏂ゆ嫹閿熸枻鎷烽敓锟�,閿熸枻鎷烽敓鏂ゆ嫹閫氶敓鏂ゆ嫹閿熸枻鎷烽敓鏂ゆ嫹閿熺殕璁规嫹閿熸枻鎷峰嫙閿熸枻鎷烽敓鏂ゆ嫹閿熸枻鎷烽敓鏂ゆ嫹閿熸彮浼欐嫹閿熸枻鎷烽敓瑙掓唻鎷烽敓鏂ゆ嫹,閿熸帴璁规嫹閿熸枻鎷烽敓鏂ゆ嫹瀹為敓琛楁枻鎷烽敓鏂ゆ嫹閿熸枻鎷烽敓鏂ゆ嫹閿熸枻鎷峰綍閿熸枻鎷峰枩閿熸枻鎷烽敓鎻紮鎷烽敓锟�
		 * 閿熸枻鎷烽敓鏂ゆ嫹閿熸枻鎷稯nDialogListener
		 */
		// 纭敓鏂ゆ嫹閿熸枻鎷峰浘閿熸枻鎷烽敓鏂ゆ嫹positive閿熸枻鎷烽敓琛楋拷
		dialog.setPositiveButton(positiveText, new DialogInterface.OnClickListener() {
			@Override
			public void onClick(DialogInterface dialogInterface, int which) {
				dialogInterface.dismiss();
				if (listener != null) {
					listener.dialogListener("positive", dialogView, dialogInterface, which);
				}
			}
			// 鍙栭敓鏂ゆ嫹閿熸枻鎷峰浘閿熸枻鎷烽敓鏂ゆ嫹negative閿熸枻鎷烽敓琛楋拷
		}).setNegativeButton(negativeText, new DialogInterface.OnClickListener() {
			@Override
			public void onClick(DialogInterface dialogInterface, int which) {
				dialogInterface.dismiss();
				if (listener != null) {
					listener.dialogListener("negative", dialogView, dialogInterface, which);
				}
			}
		}).create().show();
	}

	// 娉ㄩ敓鏂ゆ嫹閿熸枻鎷烽敓鏂ゆ嫹閿熸枻鎷烽敓鏂ゆ嫹閿燂拷
	public MikyouCommonDialog setOnDiaLogListener(OnDialogListener listener) {
		this.listener = listener;
		return this;// 閿熺獤纰夋嫹鍓嶉敓鏂ゆ嫹閿熻杩斾紮鎷�,閿熸枻鎷烽敓鏂ゆ嫹閿熸枻鎷峰紡閿熸枻鎷烽敓锟�
	}

	// 閿熸枻鎷烽敓鏂ゆ嫹涓�閿熸枻鎷烽敓鏂ゆ嫹閿熸枻鎷烽敓鏂ゆ嫹閿熸帴鍖℃嫹
	public interface OnDialogListener {
		// customView 閿熸枻鎷烽敓鏂ゆ嫹閿熸枻鎷烽敓鏂ゆ嫹閿熸彮顎额澁鎷烽敓鏂ゆ嫹閿熸枻鎷烽敓鏂ゆ嫹閿熺煫浼欐嫹閿熸枻鎷疯繙閿熸枻鎷烽敓绲璱ew,閿熸枻鎷蜂箞閿熸枻鎷烽敓鏂ゆ嫹涓簄ull
		public void dialogListener(String btnType, View customView, DialogInterface dialogInterface, int which);
	}
}
